package com.yanqu.road.entity.activity.douluodalu.data;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.douluodalu.DouLuoDaLuEnemyTip;
import com.yanqu.road.entity.activity.douluodalu.DouLuoDaLuTeamLeaveTip;
import com.yanqu.road.entity.activity.douluodalu.DouLuoDaLuUserEvent;
import com.yanqu.road.entity.activity.douluodalu.DouLuoDaLuUserPatrons;
import com.yanqu.road.entity.player.UserBaseInfo;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_c_douluodalu_user")
public class DouLuoDaLuUserData extends DataObject {

    @FieldTypeAnnotation(select = true, update = true, desc = "活动ID")
    private int activityId;
    @FieldTypeAnnotation(update = true, desc = "分组id")
    private int groupId;
    @FieldTypeAnnotation(update = true, desc = "玩家ID")
    private long userId;

    @FieldTypeAnnotation(desc = "玩家区服ID")
    private long serverId;

    @FieldTypeAnnotation(desc = "上个区域")
    private int fromRegionId;

    @FieldTypeAnnotation(desc = "当前所在区域")
    private int regionId;

    @FieldTypeAnnotation(desc = "已解锁的区域")
    private List<Integer> openRegionList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "体力")
    private int energy ;

    @FieldTypeAnnotation(desc = "总消耗体力")
    private int useEnergy;

    @FieldTypeAnnotation(desc = "上次使用体力的时间")
    private long energyLastTime ;

    @FieldTypeAnnotation(desc = "队伍ID")
    private int teamId;

    @FieldTypeAnnotation(desc = "玩家主动离开上一个队伍的时间,被踢出队伍不记录时间")
    private long lastLeaveTime;

    @FieldTypeAnnotation(desc = "玩家上次创建队伍的时间")
    private long lastCreateTime;

    @FieldTypeAnnotation(desc = "申请加入的联盟 k:联盟id v:申请时间")
    private Map<Integer, Long> applyJoinTeamMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "事件信息")
    private DouLuoDaLuUserEvent event = new DouLuoDaLuUserEvent();

    @FieldTypeAnnotation(desc = "buff")
    private Map<Integer, Integer> buffMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "魂环")
    private Map<Integer, Integer> hunHuanMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "魂环-固定加成")
    private int fixedAddition;

    @FieldTypeAnnotation(desc = "魂环-加成百分比")
    private int addition;

    @FieldTypeAnnotation(desc = "活动开始时,玩家最后一次进入活动的门客总赚钱值")
    private long allPatronsEarn;

    @FieldTypeAnnotation(desc = "门客数")
    private int patronsNum;

    @FieldTypeAnnotation(desc = "门客基础信息")
    private Map<Integer, DouLuoDaLuUserPatrons> patronsMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "门客信息最后更新时间")
    private long lastUpdateTime;

    @FieldTypeAnnotation(desc = "总魂力")
    private long hunLi;

    @FieldTypeAnnotation(desc = "总血量-总魂力的瞬时值")
    private long totalBlood;

    @FieldTypeAnnotation(desc = "玩家血量")
    private long blood;

    @FieldTypeAnnotation(desc = "玩家活动的总积分-猎魂")
    private long score;

    @FieldTypeAnnotation(desc = "仇人集合<仇人id,击杀我次数>")
    private Map<Long,Integer> enemyInfoMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "宝箱事件剩余数量")
    private Map<Integer, Integer> boxMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "完成事件的数量集合,key事件类型")
    private Map<Integer, Integer> finishEventMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "完成事件的数量集合,key区域")
    private Map<Integer, Integer> regionEventMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "用户基本信息")
    private UserBaseInfo userBaseInfo = new UserBaseInfo();

    @FieldTypeAnnotation(desc = "离队信息")
    private DouLuoDaLuTeamLeaveTip leaveTip;

    @FieldTypeAnnotation(desc = "被打败信息")
    private List<DouLuoDaLuEnemyTip> enemyTipList = new ArrayList<>();

    //缓存
    /**
     * 当前正在求助的记录
     */
    private DouLuoDaLuHelpRecordData currentHelpRecordData = null;

    /**
     * 进入区域的时间
     */
    private int entryRegionTime;
    /**
     * 是否进入活动
     */
    private boolean isEntry;

    /**
     * 仇人集合(被其他玩家探索和被标记) 血量有变化需要通知仇人
     */
    private Set<DouLuoDaLuUserData> canAttackUserSet = new ConcurrentHashSet<>();

    /**
     * 战斗数据
     */
    private DouLuoDaLuPatronsBattleData battleData;

    private int helpTimes;

    public DouLuoDaLuUserData() {
    }

    public DouLuoDaLuUserData(int activityId, int groupId, long userId) {
        this.activityId = activityId;
        this.groupId = groupId;
        this.userId = userId;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public long getServerId() {
        return serverId;
    }

    public void setServerId(long serverId) {
        if(this.serverId != serverId) {
            this.serverId = serverId;
            setUpdateOption();
        }
    }

    public int getFromRegionId() {
        return fromRegionId;
    }

    public void setFromRegionId(int fromRegionId) {
        if(this.fromRegionId != fromRegionId) {
            this.fromRegionId = fromRegionId;
            setUpdateOption();
        }
    }

    public int getRegionId() {
        return regionId;
    }

    public void setRegionId(int regionId) {
        if(this.regionId != regionId) {
            this.regionId = regionId;
        }
        setUpdateOption();
    }

    public List<Integer> getOpenRegionList() {
        return openRegionList;
    }

    public void setOpenRegionList(List<Integer> openRegionList) {
        this.openRegionList = openRegionList;
        setUpdateOption();
    }

    public void addOpenRegionId(int regionId){
        if(!openRegionList.contains(regionId)){
            openRegionList.add(regionId);
            setUpdateOption();
        }
    }

    public int getEnergy() {
        return energy;
    }

    public void setEnergy(int energy) {
        if(this.energy != energy) {
            this.energy = energy;
            setUpdateOption();
        }
    }

    public long getEnergyLastTime() {
        return energyLastTime;
    }

    public void setEnergyLastTime(long energyLastTime) {
        if(this.energyLastTime != energyLastTime) {
            this.energyLastTime = energyLastTime;
            setUpdateOption();
        }
    }

    public int getTeamId() {
        return teamId;
    }

    public void setTeamId(int teamId) {
        if(this.teamId != teamId) {
            this.teamId = teamId;
            setUpdateOption();
        }
    }

    public long getLastLeaveTime() {
        return lastLeaveTime;
    }

    public void setLastLeaveTime(long lastLeaveTime) {
        if(this.lastLeaveTime != lastLeaveTime) {
            this.lastLeaveTime = lastLeaveTime;
            setUpdateOption();
        }
    }

    public long getLastCreateTime() {
        return lastCreateTime;
    }

    public void setLastCreateTime(long lastCreateTime) {
        if(this.lastCreateTime != lastCreateTime) {
            this.lastCreateTime = lastCreateTime;
            setUpdateOption();
        }
    }

    public Map<Integer, Long> getApplyJoinTeamMap() {
        return applyJoinTeamMap;
    }

    public void addApplyJoinTeam(int teamId, long time){
        applyJoinTeamMap.put(teamId, time);
        setUpdateOption();
    }

    public void removeApplyJoinTeam(int teamId){
        if(applyJoinTeamMap.remove(teamId) != null){
            setUpdateOption();
        }
    }

    public void setApplyJoinTeamMap(Map<Integer, Long> applyJoinTeamMap) {
        this.applyJoinTeamMap = applyJoinTeamMap;
        setUpdateOption();
    }

    public DouLuoDaLuUserEvent getEvent() {
        return event;
    }

    public void setEvent(DouLuoDaLuUserEvent event) {
        this.event = event;
        setUpdateOption();
    }

    public void addBuff(int id, int count){
        if(buffMap.containsKey(id)){
            buffMap.put(id, count + buffMap.get(id));
        }else {
            buffMap.put(id, count);
        }
        setUpdateOption();
    }

    public Map<Integer, Integer> getBuffMap() {
        return buffMap;
    }

    public void setBuffMap(Map<Integer, Integer> buffMap) {
        this.buffMap = buffMap;
        setUpdateOption();
    }

    public void addHunHuan(int id, int count){
        if(hunHuanMap.containsKey(id)){
            hunHuanMap.put(id, count + hunHuanMap.get(id));
        }else {
            hunHuanMap.put(id, count);
        }
        setUpdateOption();
    }

    public Map<Integer, Integer> getHunHuanMap() {
        return hunHuanMap;
    }

    public void setHunHuanMap(Map<Integer, Integer> hunHuanMap) {
        this.hunHuanMap = hunHuanMap;
        setUpdateOption();
    }

    public long getAllPatronsEarn() {
        return allPatronsEarn;
    }

    public void setAllPatronsEarn(long allPatronsEarn) {
        if(this.allPatronsEarn != allPatronsEarn) {
            this.allPatronsEarn = allPatronsEarn;
            setUpdateOption();
        }
    }

    public long getHunLi() {
        return hunLi;
    }

    public void setHunLi(long hunLi) {
        if(this.hunLi != hunLi) {
            this.hunLi = hunLi;
            setUpdateOption();
        }
    }

    public Map<Integer, DouLuoDaLuUserPatrons> getPatronsMap() {
        return patronsMap;
    }

    public void setPatronsMap(Map<Integer, DouLuoDaLuUserPatrons> patronsMap) {
        this.patronsMap = patronsMap;
        setUpdateOption();
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(long lastUpdateTime) {
        if(this.lastUpdateTime != lastUpdateTime) {
            this.lastUpdateTime = lastUpdateTime;
            setUpdateOption();
        }
    }


    public long getTotalBlood() {
        return totalBlood;
    }

    public void setTotalBlood(long totalBlood) {
        if(this.totalBlood != totalBlood) {
            this.totalBlood = totalBlood;
            setUpdateOption();
        }
    }

    public long getBlood() {
        return blood;
    }

    public void setBlood(long blood) {
        if(this.blood != blood) {
            this.blood = blood;
            setUpdateOption();
        }
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        if(this.score != score) {
            this.score = score;
            setUpdateOption();
        }
    }

    public Map<Long, Integer> getEnemyInfoMap() {
        return enemyInfoMap;
    }

    public void setEnemyInfoMap(Map<Long, Integer> enemyInfoMap) {
        this.enemyInfoMap = enemyInfoMap;
        setUpdateOption();
    }

    public Map<Integer, Integer> getBoxMap() {
        return boxMap;
    }

    public void setBoxMap(Map<Integer, Integer> boxMap) {
        this.boxMap = boxMap;
        setUpdateOption();
    }

    public Map<Integer, Integer> getFinishEventMap() {
        return finishEventMap;
    }

    public void setFinishEventMap(Map<Integer, Integer> finishEventMap) {
        this.finishEventMap = finishEventMap;
        setUpdateOption();
    }

    public Map<Integer, Integer> getRegionEventMap() {
        return regionEventMap;
    }

    public void setRegionEventMap(Map<Integer, Integer> regionEventMap) {
        this.regionEventMap = regionEventMap;
        setUpdateOption();
    }

    public UserBaseInfo getUserBaseInfo() {
        return userBaseInfo;
    }

    public void setUserBaseInfo(UserBaseInfo userBaseInfo) {
        this.userBaseInfo = userBaseInfo;
        setUpdateOption();
    }

    public String getLeaveTipStr(){
        if(leaveTip == null){
            return "{}";
        }
        return JSON.toJSONString(leaveTip);
    }

    public DouLuoDaLuTeamLeaveTip getLeaveTip() {
        return leaveTip;
    }

    public void setLeaveTip(DouLuoDaLuTeamLeaveTip leaveTip) {
        this.leaveTip = leaveTip;
        setUpdateOption();
    }

    public List<DouLuoDaLuEnemyTip> getEnemyTipList() {
        return enemyTipList;
    }

    public void setEnemyTipList(List<DouLuoDaLuEnemyTip> enemyTipList) {
        this.enemyTipList = enemyTipList;
        setUpdateOption();
    }

    public int getUseEnergy() {
        return useEnergy;
    }

    public void setUseEnergy(int useEnergy) {
        if(this.useEnergy != useEnergy) {
            this.useEnergy = useEnergy;
            setUpdateOption();
        }
    }

    public int getFixedAddition() {
        return fixedAddition;
    }

    public void setFixedAddition(int fixedAddition) {
        if(this.fixedAddition != fixedAddition) {
            this.fixedAddition = fixedAddition;
            setUpdateOption();
        }
    }

    public int getAddition() {
        return addition;
    }

    public void setAddition(int addition) {
        if(this.addition != addition) {
            this.addition = addition;
            setUpdateOption();
        }
    }

    public int getPatronsNum() {
        return patronsNum;
    }

    public void setPatronsNum(int patronsNum) {
        if(this.patronsNum != patronsNum) {
            this.patronsNum = patronsNum;
            setUpdateOption();
        }
    }

    //缓存 =-------------------
    public DouLuoDaLuHelpRecordData getCurrentHelpRecordData() {
        return currentHelpRecordData;
    }

    public void setCurrentHelpRecordData(DouLuoDaLuHelpRecordData currentHelpRecordData) {
        this.currentHelpRecordData = currentHelpRecordData;
    }

    public int getEntryRegionTime() {
        return entryRegionTime;
    }

    public void setEntryRegionTime(int entryRegionTime) {
        this.entryRegionTime = entryRegionTime;
    }

    public Set<DouLuoDaLuUserData> getCanAttackUserSet() {
        return canAttackUserSet;
    }

    public void setCanAttackUserSet(Set<DouLuoDaLuUserData> canAttackUserSet) {
        this.canAttackUserSet = canAttackUserSet;
        setUpdateOption();
    }

    public DouLuoDaLuPatronsBattleData getBattleData() {
        return battleData;
    }

    public void setBattleData(DouLuoDaLuPatronsBattleData battleData) {
        this.battleData = battleData;
    }

    public boolean isEntry() {
        return isEntry;
    }

    public void setEntry(boolean entry) {
        isEntry = entry;
    }

    public int getHelpTimes() {
        return helpTimes;
    }

    public void setHelpTimes(int helpTimes) {
        if (!Objects.equals(this.helpTimes, helpTimes)) {
            this.helpTimes = helpTimes;
            setUpdateOption();
        }
    }

}
